import Vue from 'vue'
import App from './App.vue'
import router from './router'

import axios from 'axios'
import VueAxios from 'vue-axios'

import 'lib-flexible/flexible'

import {
  Button,
  Icon,
  Tabbar,
  TabbarItem,
  Search,
  Tab,
  Tabs,
  Toast,
  PullRefresh,
  Swipe,
  SwipeItem,
  NavBar,
  Progress,
  Empty,
  Popup

} from 'vant';

Vue
  .use(Button)
  .use(Icon)
  .use(Tabbar)
  .use(TabbarItem)
  .use(Search)
  .use(Tab)
  .use(Tabs)
  .use(Toast)
  .use(PullRefresh)
  .use(Swipe)
  .use(SwipeItem)
  .use(NavBar)
  .use(Progress)
  .use(Empty)
  .use(Popup)


axios.defaults.baseURL = 'https://apis.netstart.cn/douguo';
// 拦截器
axios.interceptors.request.use(config => {
  if (config.method === 'get') {
    config.params = config.params || {};

    // config.params.appkey = appkey
  }
  Toast.loading({
    message: '加载中...',
    //禁止穿透点击
    forbidClick: true,
    loadingType: 'spinner',
    //不会自动关闭提示
    duration: 0
  })

  return config;
}, err => {
  console.log('err ==> ', err);
  //关闭加载提示
  Toast.clear();
  return Promise.reject(err);
})

//添加一个响应之前拦截器
axios.interceptors.response.use(res => {
  //res: 服务器响应数据
  // console.log('响应数据返回给前端之前');

  //关闭加载提示
  Toast.clear();

  return res;
}, err => {
  console.log('err ==> ', err);

  //关闭加载提示
  Toast.clear();

  return Project.reject(err);
})


Vue.use(VueAxios, axios)

Vue.config.productionTip = false

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
